package com.feisuanyz.service.validation.impl;

import com.feisuanyz.dto.NotificationValidationQuery;
import com.feisuanyz.dto.RestResult;
import com.feisuanyz.entity.NotificationManagement;
import com.feisuanyz.repository.NotificationManagementRepository;
import com.feisuanyz.service.validation.NotificationValidationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 通知验证服务实现类
 */
@Service
@Slf4j
public class NotificationValidationServiceImpl implements NotificationValidationService {

    @Autowired
    private NotificationManagementRepository notificationManagementRepository;

    @Override
    public RestResult validateNotification(NotificationValidationQuery query, String operation) {
        if ("edit".equalsIgnoreCase(operation) || "delete".equalsIgnoreCase(operation)) {
            if (query.getNotificationId() == null) {
                return new RestResult("000001", "通知ID不能为空", null);
            }
            NotificationManagement notification = notificationManagementRepository.findById(query.getNotificationId()).orElse(null);
            if (notification == null) {
                return new RestResult("000001", "通知ID不存在", null);
            }
        }

        if (query.getMessage().isEmpty()) {
            return new RestResult("000001", "通知内容不能为空", null);
        }

        if (query.getIsActive() == null) {
            return new RestResult("000001", "通知是否可用必须为布尔值", null);
        }

        return new RestResult("000000", "调用成功", null);
    }
}